
var ValidationRules = {};

ValidationRules.Rules = [


    {
        elementName: '#nameInput',
        validators: ['required','minlength'],
        errorMessage: ["Please enter a Valid Name","Enter atleast 5 characters"],
        params: [true,5]
    },
    {
        elementName: '#addressInput',
        validators: ['required'],
        errorMessage: ["Please enter a Valid Address"],
        params: [true]
    },
    {
        elementName: '#phoneInput',
        validators: ['required'],
        errorMessage: ["Please enter a Valid Phone"],
        params: [true]
    },

    {
        elementName: '#emailInput',
        validators: ['required','email'],
        errorMessage: ["Please enter a Valid Input","Please enter a Valid Email"],
        params: [true,true]
    },
    {
        elementName: '#password',
        validators: ['required'],
        errorMessage: ["Please enter a title."],
        params: [true]
    }

];


ValidationRules.addRules = function () {


    $.each(ValidationRules.Rules, function (index, value) {
        if ($(value.elementName).length > 0) {
            ValidationRules.addRule(value.elementName, value.validators, value.errorMessage, value.params);
        }
        else {
            //  alert("value not there" + value.elementName);
        }

    });
}

ValidationRules.addRule = function (elementSelector, validators, errorMessagesArray, ParamArray) {

    var ruleObject = {};
    var messages = {};
    $.each(validators, function (index, value) {
        ruleObject[value] = ParamArray[index];
        messages[value] = errorMessagesArray[index];
    });

    ruleObject["messages"] = messages;

    //$(elementSelector).promise().done(function () {
    //    $(this).rules('add', ruleObject);

    //    });

    $(elementSelector).each(function (index) {
        $(this).rules('add', ruleObject);
    });


};

ValidationRules.removeRule = function (elementSelector, validationName) {
    $(elementSelector).promise().done(function () {
        $(this).rules('remove', validationName);
        return true;
    });
};

